import App from './App.vue';
import { createApp } from 'vue';
import { setupStore } from '@/sheep/store';
import { setupSheep } from '@/sheep';
import { setupRouter } from '@/sheep/router';
import ElementPlus from 'element-plus';
import zhCn from 'element-plus/dist/locale/zh-cn.mjs';

// import 'normalize.css/normalize.css';

import { initAMapApiLoader } from '@vuemap/vue-amap';
import '@vuemap/vue-amap/dist/style.css';

initAMapApiLoader({
  key: '2e3c4507c2700dc7e429cb57b627b745',
  // key: '24049076b5ad06cacb634c1a23ce6135',
  // securityJsCode:'9009d216d9557b7fa552417b5a441a89',
  securityJsCode: '80093ca495a1a30042acdd537396a833',
  v: '1.4.4',
});

async function bootstrap() {
  const app = createApp(App);
  // 注册全局整数输入指令
  app.directive('integer', {
    mounted(el) {
      const input = el.querySelector('.el-input__inner');
      if (input) {
        input.addEventListener('input', function (event) {
          const oldValue = event.target.value;
          // 移除非数字字符（允许负数：/^\-?|\D/g）
          const newValue = oldValue.replace(/\D/g, '');
          if (newValue !== oldValue) {
            event.target.value = newValue;
            input.dispatchEvent(new Event('input', { bubbles: true }));
          }
        });
      }
    },
  });
  app.use(ElementPlus, { locale: zhCn });

  setupStore(app);

  await setupSheep(app);

  await setupRouter(app).isReady();

  app.mount('#app');
}

bootstrap();
